#include <stdio.h>
#include "types.h"
#include "dynamic_array.h"

typedef struct dyn_array {
    u64* items;
    u64 length;
    u64 capacity;
} dyn_array;

void fib(dyn_array* data, u64 max) {
    switch (max) {
        case 0:
            dyn_array_append(data, 1);
            return;
        case 1:
            dyn_array_append(data, 1);
            dyn_array_append(data, 1);
            return;
        default:
            dyn_array_append(data, 1);
            dyn_array_append(data, 1);
            for (u64 i=2; i<=max; ++i) {
                dyn_array_append(data, data->items[i-2]+data->items[i-1]);
            }
            return;
    }
}

int main(void) {
    dyn_array data = {0};
    fib(&data, 10);
    printf("Fibonacci to 10:\n  ");
    for (u64 i=0; i<data.length-1; ++i) {
        printf("%ld, ", data.items[i]);
    }
    printf("%ld, ...\n", data.items[data.length-1]);
    return 0;
}